package com.qf.controller;

import com.qf.pojo.Admin;
import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.service.impl.UserServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @Author:zhangyang
 * @Date: 17:14
 * @Version 1.0
 */

@WebServlet("/findUserServlet")
public class FindUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //${pageContext.request.contextPath}/findUserServlet?id=${u.id}"

        //1)获取参数
        String id = request.getParameter("id");
        //2)调用service查询用户
        UserService userService = new UserServiceImpl() ;
        User user =  userService.findUserById(id) ;

        //3)判断如果当前用户存在
        if(user!=null){
            //将user对象存储到request对象
            request.setAttribute("user",user);
            //请求转发到update.jsp
            request.getRequestDispatcher("/update.jsp").forward(request,response);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
